package com.y17376065_yzh_FinalTest.rdtt.presenter;

import com.y17376065_yzh_FinalTest.base.base.BasePresenter;
import com.y17376065_yzh_FinalTest.base.base.BaseView;
import com.y17376065_yzh_FinalTest.rdtt.config.Config;
import com.y17376065_yzh_FinalTest.rdtt.model.NewBean;
import com.y17376065_yzh_FinalTest.rdtt.service.ApiService;
import com.y17376065_yzh_FinalTest.rdtt.service.BaseObserver;
import com.y17376065_yzh_FinalTest.rdtt.service.RetrofitManager;

import java.util.List;

import io.reactivex.disposables.Disposable;


public class NewPresenter extends BasePresenter<BaseView>
{
    public NewPresenter(BaseView view)
    {
        super(view);
    }


    public void getNewsList(String type)
    {
        subscribe
                (
                        RetrofitManager.getManager().getRetrofit().create(ApiService.class)
                                .getNewsList("toutiao".equals(type) ? "top" : type, Config.BASE_KEY),
                        new BaseObserver<List<NewBean>>()
                        {
                            @Override
                            public void onSuccess(List<NewBean> list)
                            {
                                mView.showData(list);
                            }

                            @Override
                            public void onFailed(String msg)
                            {
                                mView.showError(msg);
                            }

                            @Override
                            public void onSubcribes(Disposable d)
                            {
                                add(d);
                            }
                        }
                );
    }


}
